package com.wy2.controller;

import com.wy2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录
 */
@RestController // 返回Json数据
@CrossOrigin // 跨域访问
public class LoginController {

    @Autowired
    private UserService service;

    /**
     * 用户登录
     *
     * @param user 接收登录名 || 邮箱 || 手机号
     */
    @PostMapping("/login")
    public Map<String, Object> Login(String uname, String upassword, String code) {
        Map<String, Object> map = new HashMap<>();
        map.put("uname", uname);
        map.put("upassword", upassword);
       
        return service.login(map);
    }
    // 测试token是否有效
    @RequestMapping("/testToken")
    public Boolean testToken() {
        return true;
    }
    
    @RequestMapping("/passwordone")
	public Map<String ,Object> passwordone(String uprotectmetl){
		return service.findPhone(uprotectmetl);
	}
    /**
     * 修改密码
     * @param yzm
     * @param uidcard
     * @param pwd
     * @param upassword
     * @return
     */
	@RequestMapping("/passwordtwo")
	public Map<String ,Object> passwordtwo(String yzm,String uidcard,String pwd,String upassword){
		System.out.println("====密码为====" + upassword);
		//新密码加密
		 String  xpass2= DigestUtils.md5DigestAsHex(upassword.getBytes());
		
		 System.out.println("===加密后的密码===" + xpass2);
		return service.findPassword(yzm,uidcard,pwd,xpass2);
	}


}
